/*
* Conditions Of Use
*
* This software was developed by employees of the Sigmatrix(Beijing) Corporation.
* This software is provided by sigmatrix as a service and is expressly
* provided "AS IS."  Sigmatrix MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
* AND DATA ACCURACY.  Sigmatrix does not warrant or make any representations
* regarding the use of the software or the results thereof, including but
* not limited to the correctness, accuracy, reliability or usefulness of
* the software.
*
* Permission to use this software is contingent upon your acceptance
* of the terms of this agreement.
*
*/
package com.sigmatrix.h5.web.controller;

import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sigmatrix.h5.enums.ResponseEnum;
import com.sigmatrix.h5.response.Response;
import com.sigmatrix.h5.service.PackageScanService;
import com.sigmatrix.h5.utils.Cons;
import com.sigmatrix.h5.web.controller.common.BaseController;
import com.sigmatrix.h5.web.vo.PackageScanVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 *@ClassName: PackageScanController
 *@Description: TODO(包装管理码扫描接口访问层)
 *@author liuzelei
 *@date 2017年7月8日 下午3:12:47
 */

@ApiIgnore
@Api(tags="包装管理")
@RestController
@RequestMapping("/app/packagescan")
public class PackageScanController extends BaseController {
	/**logger record*/
	private static final Logger LOGGER = LoggerFactory.getLogger(PackageScanController.class);
	
	/**包装管理码扫描业务层接口*/
	@Autowired
	private transient PackageScanService packageScanService;
	
	@ApiOperation(value="包装管理码扫描")
	@PostMapping(value="/base")
	public Response scan( @Valid @RequestBody final PackageScanVo vo,
			final BindingResult result) {
		
		try {
			if (result.hasErrors()) {
				final String errInfo = result.getAllErrors().get(0).getDefaultMessage();
				LOGGER.error("参数验证失败{}", errInfo);
				return new Response(Cons.RESPONSE_CODE_PARAM_INVALID, errInfo);
			}
			
			return packageScanService.scan(vo);
			
//			if(Cons.PACKAGE_SCAN_LEVEL_1 == vo.getLevel()){// 1:拆补箱下的瓶码数
//				dealLevel1(vo);
//			}else if(Cons.PACKAGE_SCAN_LEVEL_2 == vo.getLevel()){// 2:拆补垛下的箱码数及垛
//				dealLevel2(vo);
//			}else if(Cons.PACKAGE_SCAN_LEVEL_2 == vo.getLevel()){// 3:补垛查询虚拟垛码 
//				dealLevel3(vo);
//			}
			
		} catch (Exception e) {
			LOGGER.error("同步经销商列表接口失败", e);
			return new Response(ResponseEnum.EXCEPTION);
		}
	}
}
